using Bee.Base.Abstractions.Navigation;
using Bee.Base.Abstractions.Plugin;
using Bee.Base.Models;
using Bee.Base.Models.Menu;
using Bee.Base.Models.Plugin;
using Bee.Plugin.First.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace Bee.Plugin.First;

public class FirstPlugin : PluginBase
{
    public FirstPlugin(IOptions<AppSettings> appSettings) : base(appSettings)
    {
    }

    public override string PluginName { get; } = "First";

    public override R Execute<T, R>(string methodName, T parameters)
        where T : default
        where R : class
    {
        return methodName switch
        {
            "method1" => Method1(parameters as MethodParamter) as R,
            _ => throw new NotImplementedException("插件方法不存在")
        };
    }

    public override void RegisterServices(IServiceCollection services)
    {
        services.AddTransient<IPlugin, FirstPlugin>();
        services.AddSingleton<FirstViewModel>();
        services.AddSingleton<INavigationCommand, FirstPluginNavigationCommand>();
    }

    public override void ConfigureMenu(MenuConfigurationContext menuContext)
    {
        var item = menuContext.Menus.FirstOrDefault(a => a.Key == "Home");
        if (item is null) return;
        
        item.Items.Add(new MenuItem()
        {
            Key = "UmlGenerator",
            LocaleKey = "Menu.Sider.UmlGenerator",
            GroupLocaleKey = "Menu.Sider.DevTools",
            CommandType = "Navigate",
            CommandParameter = "UmlGenerator"
        });
    }
    
    private PluginResult Method1(MethodParamter para) => new PluginResult(true);
}

public class MethodParamter
{
    public string MethodName { get; set; }
}